﻿using JobSchedule.Base;
using System;
using Topshelf;

namespace JobSchedule
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var rc = HostFactory.Run(config =>
            {
                config.RunAsLocalSystem();
                config.SetServiceName("CubeIISCheck");
                config.SetDisplayName("CUBE后台任务程序-cube宕机处理");
                config.Service<Program>(c =>
                {
                    c.ConstructUsing(name => new Program());
                    c.WhenStarted(p => p.Start());
                    c.WhenStopped(p => p.Stop());
                });
            });

            var exitCode = (int)Convert.ChangeType(rc, rc.GetTypeCode());
            Environment.ExitCode = exitCode;
        }

        void Start()
        {
            ScheduleBase.Scheduler.Start();//启动调度器
            ScheduleBase.InitScheduleJobs();//初始化调度任务

            //Console.ReadLine();
        }

        void Stop()
        {
            ScheduleBase.Scheduler.Shutdown();
        }
    }
}
